import request from '../utils/request'

// 加载商品列表
export const productGet = (page=1,size=12,condition={})=>{
  let skip = (page-1)*size  //根据页码算出需要跳过的数据条数
  let where = {}  //完整的查询参数对象
  if(condition.fnjiType){
    where.fnjiType = condition.fnjiType
  }
  if(condition.name){
    // where.name = condition.name  //精准匹配
    where.name = {"$regex":condition.name,"$options":"i"}  //模糊查询、正则匹配
  }
  let wh = JSON.stringify(where) //将json对象转为json字符串
  return request.get(`/classes/product?count=1&limit=${size}&skip=${skip}&where=${wh}`)
}

// 编辑商品
export const productPut = (objectId,editData)=>{ //editData是需要提交更新的数据包对象
  return request.put(`/classes/product/${objectId}`,editData)
}